package com.hualan.sfzy.controller.course;

import com.hualan.sfzy.entity.course.CourseEvaluate;
import com.hualan.sfzy.service.course.CourseEvaluateService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CourseEvaluateController {
    @Autowired
    private CourseEvaluateService courseEvaluateService;
    @PostMapping("/courseEvaluate")
    public Result add(@RequestBody CourseEvaluate courseEvaluate) {
        return courseEvaluateService.add(courseEvaluate)>0 ?Result.success():Result.error();
    }
    @PutMapping("/courseEvaluate")
    public Result edit(@RequestBody CourseEvaluate courseEvaluate) {
        return courseEvaluateService.edit(courseEvaluate)>0 ?Result.success():Result.error();
    }
    @DeleteMapping("/courseEvaluate/{id}")
    public Result remove(@PathVariable int id) {
        return courseEvaluateService.remove(id)>0 ?Result.success():Result.error();
    }
    @DeleteMapping("/courseEvaluate")
    public Result removeBatch(Integer[] ids) {
        return courseEvaluateService.removeBatch(ids)>0 ?Result.success():Result.error();
    }
    @GetMapping("/courseEvaluate")
    public Result find() {
        List<CourseEvaluate> list = courseEvaluateService.find();
        return Result.success(list);
    }
    @GetMapping("/courseEvaluate/{id}")
    public Result findById(@PathVariable int id) {
        CourseEvaluate courseEvaluate = courseEvaluateService.findById(id);
        return Result.success(courseEvaluate);
    }
    @GetMapping("/courseEvaluate/page")
    public Result findByPage(
            @RequestParam(value = "pageNum",defaultValue = "1",required = false)
            Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "5",required = false)
            Integer pageSize, CourseEvaluate courseEvaluate) {
        Map<String,Object> map = courseEvaluateService.findByPage(pageNum, pageSize, courseEvaluate);
        return Result.success(map);
    }

    @GetMapping("/courseEvaluate/count")
    public Result getEvaluationCount(@RequestParam Integer courseId) {
        int count = courseEvaluateService.countByCourseId(courseId);
        return Result.success(count);
    }
}

